package com.example.sixgod;

import android.content.Intent;
import android.media.Image;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.SimpleAdapter;
import android.widget.Spinner;

import com.google.android.material.bottomnavigation.BottomNavigationView;

import androidx.annotation.AnyThread;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;

import com.example.sixgod.databinding.ActivityMainBinding;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends AppCompatActivity {
    private List<Map<String,Object>> data;

   private guaDatabase database;
   private Textchange textchange;
   private SixNumer sixNumer;
   private Button button;

    Spinner spinner1,spinner2,spinner3,spinner4,spinner5,spinner6;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        spinner1 = findViewById(R.id.spinner);
        spinner2 = findViewById(R.id.spinner2);
        spinner3 = findViewById(R.id.spinner3);
        spinner4 = findViewById(R.id.spinner4);
        spinner5 = findViewById(R.id.spinner5);
        spinner6 = findViewById(R.id.spinner6);
        button = findViewById(R.id.analyze);
        getData();
        sixNumer= new ViewModelProvider(this, new ViewModelProvider.AndroidViewModelFactory(getApplication())).get(SixNumer.class);
        SimpleAdapter simpleAdapter = new SimpleAdapter(this, data, R.layout.picture_item, new String[] {"Icon"}, new int[] {R.id.imageView});
        spinner1.setAdapter(simpleAdapter);
        spinner2.setAdapter(simpleAdapter);
        spinner3.setAdapter(simpleAdapter);
        spinner4.setAdapter(simpleAdapter);
        spinner5.setAdapter(simpleAdapter);
        spinner6.setAdapter(simpleAdapter);
        database= guaDatabase.getInstance(MainActivity.this);
        textchange=new Textchange();
        textchange.change(database,this);
        spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                sixNumer.numbers[0]=i;
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {
                sixNumer.numbers[0]=0;
            }
        });
        spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                sixNumer.numbers[1] = i;
            }
            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {
                sixNumer.numbers[1] = 0;
            }
        });
        spinner3.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                sixNumer.numbers[2] = i;
            }
            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {
                sixNumer.numbers[2] = 0;
            }
        });
        spinner4.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                sixNumer.numbers[3] = i;
            }
            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {
                sixNumer.numbers[3] = 0;
            }
        });
        spinner5.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                sixNumer.numbers[4] = i;
            }
            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {
                sixNumer.numbers[4] = 0;
            }
        });
        spinner6.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                sixNumer.numbers[5] = i;
            }
            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {
                sixNumer.numbers[5] = 0;
            }
        });
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle = new Bundle();
                bundle.putIntArray("numers", sixNumer.numbers);
                Intent intent = new Intent(MainActivity.this, MainActivity2.class);
                intent.putExtras(bundle);
                startActivity(intent);
            }
        });



    }

    private void getData() {
         data = new ArrayList<Map<String,Object>>();
         Map<String,Object> map = new HashMap<String,Object>();
         map.put("Icon",R.mipmap.laoyang);
         data.add(map);
         map = new HashMap<String,Object>();
         map.put("Icon",R.mipmap.laoying);
         data.add(map);
        map = new HashMap<String,Object>();
        map.put("Icon",R.mipmap.shaoyang);
        data.add(map);
        map = new HashMap<String,Object>();
        map.put("Icon",R.mipmap.shaoying);
        data.add(map);

    }

}